#ifndef CAMERA_HPP
#define CAMERA_HPP
#include <glog/logging.h>
// #include <openni2/OpenNI.h>
#include <ros/ros.h>
#include <sensor_msgs/Range.h>
#include <std_srvs/SetBool.h>
#include <sys/mman.h>

#include <Eigen/Dense>
#include <mutex>
#include <vector>

#include "as_camera_sdk_api.hpp"
#include "serial.hpp"

struct IndexPosition {
    uint32_t index;
    uint16_t position;
};

class Camera : public Serial {
  public:
    Camera(std::shared_ptr<ros::NodeHandle> node_handle_ptr,
           const std::string &serial_port);
    ~Camera();
    Camera(const Camera &) = default;
    Camera &operator=(const Camera &) = default;

    void CameraRxThread();

    void ParseData(std::vector<uint8_t> &data);

    // void Publish(const sensor_msgs::Camera &imu);

    bool SetRunning(const bool &running);

    bool SwitchCallBack(std_srvs::SetBool::Request &req,
                        std_srvs::SetBool::Response &res);

    static void Attached(AS_CAM_ATTR_S *attr, void *this_ptr);

    static void Detached(AS_CAM_ATTR_S *attr, void *this_ptr);

    static void FrameCallback(AS_CAM_PTR device_ptr,
                              const AS_SDK_Data_s *sdk_data_ptr,
                              void *this_ptr);

  private:
    std::shared_ptr<ros::NodeHandle> node_handle_ptr_;
    // ros::Publisher publisher_;
    ros::ServiceServer switch_;
    std::string name_;
    bool is_running_{false}; // 程序是否运行
    bool is_start_{false};   // 硬件是否运行
    // bool is_right_bandrate_{false};
    std::vector<ros::Time> times_;
    std::mutex mutex_;
    AS_CAM_ATTR_S attributes_;
    AS_CAM_PTR device_ptr_;
    AS_CAM_Parameter_s parameter_;
};
#endif